<?php
namespace app\www\controller;
use think\Db;
class Article
{
    public function article($id='')
    {

        if($id == ''){
            echo " <script type='text/javascript'> window.history.go(-1); </script>";    
            exit;
        }
        
        $sys = \app\common\model\Data::getSys();
        $ext = \app\common\model\Data::getExt();

        $nav = Db::query( " SELECT title,url FROM nav WHERE cat_id = 1 AND status = 0 ORDER BY sort ASC " );

        //首页新闻
        $article = Db::query( " SELECT title,content,create_time FROM article WHERE id = ? " , [ $id ] );

        if(!$article){
            echo " <script type='text/javascript'> window.history.go(-1); </script>";    
            exit;
        }

        $article['0']['day']       =  date('d', $article['0']['create_time']); 
        $article['0']['mar']       =  date('Y', $article['0']['create_time']);

        //幻灯
        $slide = Db::query( " SELECT pic,url FROM slide WHERE cat_id = 6 AND status = 0 ORDER BY sort ASC " );

        //推送
        $rec10 = Db::query( " SELECT id,title,description,create_time FROM article WHERE rec_id = 10 AND status = 0 " );
        if($rec10){
            $rec10['0']['day']       =  date('d', $rec10['0']['create_time']); 
            $rec10['0']['mar']       =  date('Y', $rec10['0']['create_time']);    
        }else{
            $rec10['0']['day']          = '';
            $rec10['0']['mar']          = '';
            $rec10['0']['id']           = '';
            $rec10['0']['title']        = '';
            $rec10['0']['description']  = '';
            $rec10['0']['create_time']  = '';
        }
        

        //相关新闻
        $rec11 = Db::query( " SELECT id,title,create_time FROM article WHERE rec_id = 11 AND status = 0 " );

        $d = [
            'sys'       => $sys, 
            'ext'       => $ext,
            'article'   => $article,
            'slide'     => $slide,
            'rec10'     => $rec10,
            'rec11'     => $rec11,
            'nav'       => $nav,
        ];
        
        return view('',$d);
    }


    public function lists($keyword = ''){
    
        $sys = \app\common\model\Data::getSys();
        $ext = \app\common\model\Data::getExt();

        $nav = Db::query( " SELECT title,url FROM nav WHERE cat_id = 1 AND status = 0 ORDER BY sort ASC " );

        $param = "%{$keyword}%";
        $article = Db::query( " SELECT id,title,description FROM article WHERE cat_id = 60 AND title like ? AND status = 0 ORDER BY sort ASC " , [$param] );
        
    
        $d = [
            'sys'       => $sys, 
            'ext'       => $ext,
            'nav'       => $nav,
            'article'   => $article,
        ];
        
        return view('',$d);
    }


    //获取碎片，和系统配置
    public function demo(){
        $title = \app\common\model\Data::getSys("title");
        $index = \app\common\model\Data::getExt("index");
        
        t([$title,$index]);
    }
}
